package com.rq.demo.controller;

import android.app.VoiceInteractor;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;


import com.rq.base.reflect.activity.Act_onLocalVoiceInteractionStarted;
import com.rq.base.ui.BaseController;
import com.rq.base.ui.impl.OnClick;
import com.rq.base.util.LOG;
import com.rq.base.util.LanguageUtil;
import com.rq.demo.R;

import java.util.Locale;


public class MainController extends BaseController implements View.OnClickListener, Act_onLocalVoiceInteractionStarted {
//
    //    , DownloadIntentService.DownloadListener
//    LanguageUtil mLanguageUtil;

    @Override
    public int getLayoutId() {
        return R.layout.act_login;
    }

    //    @Override
//    public void onViewCreated(Bundle savedInstanceState) {
//        super.onViewCreated(savedInstanceState);
////        Downloader.getInstance().init(getActivity()).addDownloadListener(this).check();
////        mLanguageUtil = new LanguageUtil(getActivity());
////        IntentFilter filter = new IntentFilter();
////        filter.addAction(Intent.ACTION_PACKAGE_INSTALL);
////        filter.addAction(Intent.ACTION_PACKAGE_ADDED);
////        filter.addAction(Intent.ACTION_TIME_TICK);
////        getActivity().registerReceiver(new InstallBroadcast(), filter);
//    }
//
//    /**
//     * 这里是简单示例 具体下标和 {@link LanguageUtil.LANGUAGE 绑定}
//     */
//    private static int lan = 1;
//
    @Override
    @OnClick({R.id.btn_test, R.id.btn_download, R.id.btn_lock, R.id.btn_recycler, R.id.btn_net, R.id.btn_fra})
    public void onClick(View v) {
        if (v.getId() == R.id.btn_test) {
//            LOG.e("MainController", "onClick.before.language:" + lan);
//            lan = 1 - lan;
//            LOG.e("MainController", "onClick.old.language:" + lan);
//            Locale sa = LanguageUtil.getLocale(lan);
//            setData2View(R.id.tv_show, sa.getLanguage());
//            mLanguageUtil.saveSelect(sa);
            setData2View(R.id.btn_test, "1111111111");
            Bundle intent = new Bundle();
            intent.putString("name", "Test Voice Interaction");
            reflectActivity("startLocalVoiceInteraction", intent);
        } else if (v.getId() == R.id.btn_lock) {
            startActivity(new Intent(getContext(), LockActivity.class));
        } else if (v.getId() == R.id.btn_recycler) {
            open(RecyclerController.class);
        } else if (v.getId() == R.id.btn_net) {
            open(NetController.class);
        } else if (v.getId() == R.id.btn_fra) {
            open(FragmentTest.class);
        }
    }
//
//    @Override
//    public boolean underStatusBar() {
//        return false;
//    }
//
//    @Override
//    public boolean isStatusBarTextDark() {
//        return true;
//    }

    @Override
    public void onLocalVoiceInteractionStarted() {
        VoiceInteractor interactor = (VoiceInteractor) reflectActivity("getVoiceInteractor");
        setData2View(R.id.btn_test, "onLocalVoiceInteractionStarted");
    }

    //    @Override
//    public void onProgress(int progress) {
//        setData2View(R.id.btn_test, "已下载:" + progress);
//    }
//
//    @Override
//    public void onCompleted(File file) {
//        String FileProviderName = BuildConfig.APPLICATION_ID + ".fileProvider";//provider
//        DownloadUtil.installApp(getActivity(), file, FileProviderName);
//    }
//
//    @Override
//    public void onError() {
//
//    }
//
//    @Override
//    public void onActivityDestroy() {
//        super.onActivityDestroy();
//        Downloader.getInstance().removeDownloadListener(this);
//    }
}
